Repository navigation
Conversation
Undo for deleted nodes were recorded in selection order, witout sorting the nodes into tree order. Undo then restored siblings out of order, so `move_child` could be called with an index that didn't exist yet. PR description AI disclosure: Asked Claude whether the fix would have side-effects or no. Also asked it to judge this PR. After deleting multiple sibling nodes selected in a non-top-to-bottom order (Selecting in the 2D viewport through mouse-hodl, or holding ctrl and clicking bottom-up in the Scene dock), undoing the deletions prints `ERROR: Invalid new child index: (previous index number).` This happens because in `SceneTreeDock::_delete_confirm`, the undo methods for each deleted node are restored one by one in the order of the selection, so a node can be restored before its siblings, at a point where its original index doesn't exist yet. For whatever reason, the selection was being sorted with `Node::Comparator` only for the animation track cleanup after the undo methods had already been recorded. This PR moves the same sort before recording, so that undo always restores nodes in ascending index order. This means that the animation track cleanup will work as it did before. - Closes godotengine#125903 Tested with the MRP from the issue: - Box select the four Icon nodes, delete, undo: no error, nodes restored in original order. - Ctrl-click nodes bottom-up in the Scene dock, delete, undo - Cut (Ctrl+X) + undo - Redo after undo Reproducible since at least 4.6.3 according to the issue (haven't checked myself), so not a recent regression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Undo for deleted nodes were recorded in selection order, without sorting the nodes into tree order. Undo then restored siblings out of order, so
move_childcould be called with an index that didn't exist yet.PR description
AI disclosure: Double-checked by asking claude chat whether the fix would have side-effects or no. Also asked it to judge this PR.
After deleting multiple sibling nodes selected in a non-top-to-bottom order (Selecting in the 2D viewport through mouse-hold, or holding ctrl and clicking bottom-up in the Scene dock), undoing the deletions prints
ERROR: Invalid new child index: (previous index number).This happens because in
SceneTreeDock::_delete_confirm, the undo methods for each deleted node are restored one by one in the order of the selection, so a node can be restored before its siblings, at a point where its original index doesn't exist yet.For whatever reason, the selection was being sorted with
Node::Comparatoronly for the animation track cleanup after the undo methods had already been recorded.This PR moves the same sort before recording, so that undo always restores nodes in ascending index order. This means that the animation track cleanup will work as it did before.
Tested with the MRP from the issue:
Reproducible since at least 4.6.3 according to the issue (haven't checked myself), so not a recent regression.